﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace SlaktDataReader
{
    [Serializable]
    public class MoveOutBook : BookBase<MoveOutBookRecord>, SlaktDataReader.IBooks
    {

        public override ObservableCollection<MoveOutBookRecord> Items { get; set; }
        public override BookTypes BookType { get { return BookTypes.MoveOut; } }

        public MoveOutBook(string fileName)
        {
            this.FileName = FileName;
            _init();
            ReadBook();
        }

        public MoveOutBook() { _init(); }

        protected override void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            MoveOutBook rv;
            BWArgs arg = e.Argument as BWArgs;

            switch (arg.FileType)
            {
                case BWArgs.BookFileType.Text:
                    rv = _ReadTextFile(arg.FileName);
                    e.Result = rv;
                    break;
                case BWArgs.BookFileType.Excel:
                    rv = _ReadExcelFile(arg.FileName);
                    e.Result = rv;
                    break;
                default:
                    break;
            }


        }

        protected override void bwLoad_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {

            if (e.Result != null)
            {
                MoveOutBook rv = e.Result as MoveOutBook;
                if (rv.Items != null)
                {
                    //this.Area = rv.Area;
                    //this.EditedBy = rv.EditedBy;

                    //this.Parish = rv.Parish;
                    //this.Period = rv.SDCode;
                    //this.Source = rv.Source;
                    //this.UpdateDate = rv.UpdateDate;

                    this.Items = rv.Items;

                    readSuccess();

                    return;
                }
            }
            readFail();
        }

        protected override void bwLoad_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
        }

        private MoveOutBook _ReadTextFile(string fName)
        {
            MoveOutBookTextFile reader = new MoveOutBookTextFile();
            MoveOutBook bBook = new MoveOutBook();
            if (reader.Read(fName) > 0)
            {
                bBook.Items = new ObservableCollection<MoveOutBookRecord>(reader.Records);
                bBook.FileName = fName;
                // Copy other data
                return bBook;
            }
            return null;
        }

        private MoveOutBook _ReadExcelFile(string fName)
        {
            return null;
        }

        public override void ExportBook()
        {
            exportFail();
        }
    }

    [Serializable]
    public class MoveOutBookRecord
    {
        private int rowID = 0;
        public int RowID { get { return rowID; } set { rowID = value; IsChanged = true; } }

        private string pageNo = null;
        public string PageNo { get { return pageNo; } set { pageNo = value; IsChanged = true; } }

        private string ordNo = null;
        public string OrdNo { get { return ordNo; } set { ordNo = value; IsChanged = true; } }

        private string moveOutDate = null;
        public string MoveOutDate { get { return moveOutDate; } set { moveOutDate = value; IsChanged = true; } }

        private char gender = 'U';
        public char Gender { get { return gender; } set { gender = value; IsChanged = true; } }

        private string attestNo;
        public string AttestNo { get { return attestNo; } set { attestNo = value; IsChanged = true; } }

        private string title = null;
        public string Title { get { return title; } set { title = value; IsChanged = true; } }

        private string firstName = null;
        public string FirstName { get { return firstName; } set { firstName = value; IsChanged = true; } }

        private string surName = null;
        public string SurName { get { return surName; } set { surName = value; IsChanged = true; } }

        private string fRAdress = null;
        public string FRAddress { get { return fRAdress; } set { fRAdress = value; IsChanged = true; } }

        private string nFRAddress = null;
        public string NFRAddress { get { return nFRAddress; } set { nFRAddress = value; IsChanged = true; } }

        private string toAddress = null;
        public string ToAdress { get { return toAddress; } set { toAddress = value; IsChanged = true; } }

        private string nToAddress = null;
        public string NToAddress { get { return nToAddress; } set { nToAddress = value; IsChanged = true; } }

        private string fDate = null;
        public string BornDate { get { return fDate; } set { fDate = value; IsChanged = true; } }

        private string fAddress = null;
        public string BornAddress { get { return fAddress; } set { fAddress = value; IsChanged = true; } }

        private string nFAddress = null;
        public string NBornAddress { get { return nFAddress; } set { nFAddress = value; IsChanged = true; } }

        private string extra1 = null;
        public string Extra1 { get { return extra1; } set { extra1 = value; IsChanged = true; } }

        private string extra2 = null;
        public string Extra2 { get { return extra2; } set { extra2 = value; IsChanged = true; } }

        private string extra3 = null;
        public string Extra3 { get { return extra3; } set { extra3 = value; IsChanged = true; } }

        private string mtitel = "";
        public string MaleTitle { get { return mtitel; } set { mtitel = value; IsChanged = true; } }

        private string mfnamn = "";
        public string MaleFirstName { get { return mfnamn; } set { mfnamn = value; IsChanged = true; } }

        private string menamn = "";
        public string MaleSurName { get { return menamn; } set { menamn = value; IsChanged = true; } }

        private string ktitel = "";
        public string FemaleTitle { get { return ktitel; } set { ktitel = value; IsChanged = true; } }

        private string kfnamn = "";
        public string FemaleFirstName { get { return kfnamn; } set { kfnamn = value; IsChanged = true; } }

        private string kenamn = "";
        public string FemaleSurName { get { return kenamn; } set { kenamn = value; IsChanged = true; } }

        private string uppdaterat = "";
        public string Updated { get { return uppdaterat; } set { uppdaterat = value; IsChanged = true; } }

        [XmlIgnore]
        public bool IsChanged { get; set; }

    }
}
